#include "TcpParserSender.h"


CTcpParserSender::CTcpParserSender(void)
{
}


CTcpParserSender::~CTcpParserSender(void)
{
}

bool CTcpParserSender::append_package( const _tag_header& header, const void* p_data )
{
	assert(0 != header.length);
	assert(NULL != p_data);

	if ((0 == header.length) || (NULL == p_data))
	{
		return false;
	}

	_tag_header_for_storage header_for_storage;

	header_for_storage.data_hash = crc16::calc_crc16(reinterpret_cast<const unsigned char*>(p_data), header.length);
	header_for_storage.length = header.length;
	header_for_storage.number = header.number;

	if (false == _memory_allocator.append_data(_package_bound_begin.bound_string, _package_bound_begin.string_length))
		return false;

	if (false == _memory_allocator.append_data(&header_for_storage, sizeof(header_for_storage)))
		return false;

	if (false == _memory_allocator.append_data(p_data, header_for_storage.length))
		return false;

	if (false == _memory_allocator.append_data(_package_bound_end.bound_string, _package_bound_end.string_length))
		return false;

	return true;
}

const void* CTcpParserSender::get_data( unsigned long& data_size )
{
	return _memory_allocator.get_data(data_size);
}
